{extend name="../admin/common/base" /}
{block name="body"}
<div class="layui-fluid" >
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body">
                            <div class="layui-form" lwid100 iwid400 lay-filter="form">
                                <!--//解析HTML表单-->
                                {foreach $options as $key=>$vo}
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{$vo.title}</label>
                                    <div class="layui-input-inline">
                                        {switch $vo.type }
                                        {case select}
                                        <select name="{$key}" lay-verify="{$vo.rule}">
                                            {foreach $vo['options'] as $k=>$v}
                                                <option {if $k == $options_val[$key]}selected{/if} value="{$k}">{$v}</option>
                                            {/foreach}
                                        </select>
                                        {/case}
                                        {case checkbox}
                                        {foreach $vo['options'] as $k=>$v}
                                            <input lay-verify="{$vo.rule}"  {if $v == $options_val[$key]}checked{/if} type="checkbox" name="{$key}[]" value="{$k}" title="{$v}">
                                        {/foreach}
                                        {/case}
                                        {case textarea}
                                        <textarea placeholder="" name="{$key}"  lay-verify="{$vo.rule}"
                                                  class="layui-textarea">{$options_val[$key]}</textarea>
                                        {/case}
                                        {case num}
                                        <input type="number" class="layui-input" lay-verify="{$vo.rule}" name="{$key}"
                                               value="{$options_val[$key]}" autocomplete="off"
                                               class="layui-input">
                                        {/case}
                                        {default /}
                                        <input type="text" class="layui-input {$vo.type}" lay-verify="{$vo.rule}"
                                               name="{$key}"
                                               value="{$options_val[$key]}" autocomplete="off"
                                               class="layui-input">
                                        {/switch}
                                    </div>
                                    <div class="layui-form-mid layui-word-aux pass-tips">{$vo.tips|raw|default=''}</div>
                                </div>
                                {/foreach}
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="form">保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="my_js"}
<script>
    layui.use(['element', 'admin', 'form', 'laydate'], function () {
        var element = layui.element
            , admin = layui.admin
            , $ = layui.$
            , laydate = layui.laydate
            , form = layui.form;

        laydate.render({
            elem: ".datetime"
            , type: 'datetime'
        });
        laydate.render({
            elem: ".date"
            , type: 'date'
        });
        laydate.render({
            elem: ".time"
            , type: 'time'
        });
        form.on('submit(form)', function (data) {
            admin.ajax("admin/addons/{:input('d_id')}", data.field, function (data) {
                if (data.code == 1001) {
                    if ($('#layui-icon-refresh', parent.document)) {
                        $('#layui-icon-refresh', parent.document).click();
                    }
                    layer.confirm(data.msg + ',是否继续添加?', {
                        icon: 3,
                        title: '提示',
                        btn: ['继续', '返回']
                    }, function (index) {
                        location.reload();
                    }, function () {
                        admin.closeSelf()
                    });
                } else {
                    layer.msg(data.msg);
                }
            }, '', 'put');
        });
    });
</script>
{/block}